﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Zombie_Demo
{
    public static class ContentManager
    {
        private static Dictionary<string, Texture2D> textures;
        private static Microsoft.Xna.Framework.Content.ContentManager Content;

        public static void Init(Game1 game)
        {
            textures = new Dictionary<string, Texture2D>();
        }

        public static void SetContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            Content = content;
            Content.RootDirectory = "Content";
        }

        public static bool LoadTexture(string key, string filename)
        {
            try{
                textures.Add(key, Content.Load<Texture2D>(filename));
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public static Texture2D GetTexture(string key)
        {
            if (textures.ContainsKey(key))
                return textures[key];
            else
            {
                bool didLoad = LoadTexture(key, key);
                if (didLoad)
                    return textures[key];
                else
                    return textures["Error"];
            }
        }
    }
}
